

#ifndef _UC_LY_H
#define _UC_LY_H

#include "zAdAChar.h"
#include "zacadstrc.h"
#include "zacarray.h"
#include "zdbsymtb.h"
#include "zdbxrecrd.h"

class UcLySystemInternals;
class UcLyRelExpr 
{
public:
	virtual ~UcLyRelExpr(){}
    virtual const ZTCHAR * getVariable() const = 0;
    virtual const ZTCHAR * getConstant() const = 0;
};

class UcLyAndExpr 
{
public:
    virtual ~UcLyAndExpr() { }
    virtual const UcArray<UcLyRelExpr*>& getRelExprs() const = 0;
};

class UcLyBoolExpr 
{
public:
    virtual ~UcLyBoolExpr() { }
    virtual const UcArray<UcLyAndExpr*>& getAndExprs() const = 0;
};

#ifndef HIMAGELIST
struct _IMAGELIST;
typedef struct _IMAGELIST* HIMAGELIST;
#endif

class UcLyLayerFilter : public UcRxObject, public UcHeapOperators
{
public:
    UCRX_DECLARE_MEMBERS(UcLyLayerFilter);
    UcLyLayerFilter ();
    virtual ~UcLyLayerFilter ();

    virtual const ZTCHAR * name() const;
    virtual Ucad::ErrorStatus setName(const ZTCHAR *);
    virtual bool allowRename() const;

    virtual Ucad::ErrorStatus getImages(HIMAGELIST& imageList, ZSoft::UInt32& normalImage, ZSoft::UInt32& selected) const;

    virtual UcLyLayerFilter* parent() const;

    virtual const UcArray<UcLyLayerFilter*>& getNestedFilters() const;
    virtual Ucad::ErrorStatus addNested(UcLyLayerFilter* filter);
    virtual Ucad::ErrorStatus removeNested(UcLyLayerFilter* filter);

    virtual Ucad::ErrorStatus generateNested();

    virtual bool dynamicallyGenerated() const;

    virtual bool allowNested() const;

    virtual bool allowDelete() const;

    virtual bool isProxy() const;

    virtual bool isIdFilter() const;

    virtual bool filter(UcDbLayerTableRecord* layer) const;

    enum DialogResult {kOk = 0, kCancel=1, kUseDefault = 2};
    virtual  DialogResult showEditor();

    virtual const ZTCHAR * filterExpression() const;
    virtual Ucad::ErrorStatus setFilterExpression(const ZTCHAR * expr);

    virtual const UcLyBoolExpr* filterExpressionTree() const;

    virtual bool compareTo(const UcLyLayerFilter* pOther) const;

    virtual Ucad::ErrorStatus readFrom(UcDbDxfFiler* filer);
    virtual Ucad::ErrorStatus writeTo(UcDbDxfFiler* pFiler) const;

private:
    void *mp_impObj;
    friend class UcLySystemInternals;

protected:
    UcLyLayerFilter(UcLySystemInternals*);
};

class UcLyLayerGroup : public UcLyLayerFilter
{
public:
    UCRX_DECLARE_MEMBERS(UcLyLayerGroup);
    UcLyLayerGroup();

    virtual Ucad::ErrorStatus        addLayerId    (const UcDbObjectId& id);
    virtual Ucad::ErrorStatus        removeLayerId (const UcDbObjectId& id);
    virtual const UcDbObjectIdArray& layerIds      () const;

protected:
    UcLyLayerGroup(UcLySystemInternals*);
};

class UcLyLayerFilterManager
{
public:
	virtual ~UcLyLayerFilterManager(){}
    virtual Ucad::ErrorStatus getFilters(UcLyLayerFilter*& pRoot, UcLyLayerFilter*& pCurrent) = 0;

    virtual Ucad::ErrorStatus setFilters( const UcLyLayerFilter* pRoot, const UcLyLayerFilter* pCurrent) = 0;
};

UcLyLayerFilterManager* uclyGetLayerFilterManager(UcDbDatabase* pDb);

#endif  
